package kr.saeildamil.androidstudy_second28;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.webkit.WebView.FindListener;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter {
	ArrayList<Item>itemList;
	Context context;

	public MyAdapter(ArrayList<Item> itemList, Context context) {
		super();
		this.itemList = itemList;
		this.context = context;
	}

	@Override
	public int getCount() {
		return itemList.size();
	}

	@Override
	public Object getItem(int position) {
		return itemList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout layout=null;
		TextView itemName=null;
		TextView makerName=null;
		TextView itemPrice=null;
		
		if(convertView==null){
			layout=new LinearLayout(context);
			layout.setOrientation(LinearLayout.HORIZONTAL);
			itemName=new TextView(context);
			makerName=new TextView(context);
			itemPrice=new TextView(context);
			itemName.setTag(1);
			makerName.setTag(2);
			itemPrice.setTag(3);
			LayoutParams params=new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
			layout.addView(itemName, params);
			layout.addView(makerName, params);
			layout.addView(itemPrice, params);
			convertView=layout;
		}
		
		itemName=(TextView) convertView.getTag(1);
		itemName.setText(itemList.get(position).getItemName());
		makerName=(TextView) convertView.getTag(2);
		makerName.setText(itemList.get(position).getItemName());
		itemPrice=(TextView) convertView.getTag(3);
		itemPrice.setText(Integer.toString(itemList.get(position).getItemPrice()));
		return layout;
	}

}
